package com.clock.shop.service.impl;

import java.util.List;

import com.clock.shop.domain.ShopEmployee;
import com.clock.shop.domain.vo.EmployeeVo;
import com.clock.shop.mapper.ShopEmployeeMapper;
import com.clock.shop.service.IShopEmployeeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 职工Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Service
public class ShopEmployeeServiceImpl implements IShopEmployeeService {
    @Autowired
    private ShopEmployeeMapper shopEmployeeMapper;

    @Autowired
    private ShopShopServiceImpl shopShopService;

    @Override
    public List <ShopEmployee> selectShopEmployeeListByShopId(Long shopId) {
        return shopEmployeeMapper.selectShopEmployeeListByShopId(shopId);
    }

    /**
     * 查询职工
     *
     * @param employeeId 职工主键
     * @return 职工
     */
    @Override
    public EmployeeVo selectShopEmployeeByEmployeeId(Long employeeId) {
        // 根据员工id查询员工信息
        ShopEmployee shopEmployee = shopEmployeeMapper.selectShopEmployeeByEmployeeId(employeeId);
        EmployeeVo employeeVo = new EmployeeVo();
        BeanUtils.copyProperties(shopEmployee, employeeVo);
        // 根据店铺id查询店铺信息并封装到员工信息中
        employeeVo.setShopName(shopShopService.selectShopShopByShopId(shopEmployee.getShopId()).getShopName());
        return employeeVo;
    }


    /**
     * 查询职工列表
     *
     * @param shopEmployee 职工
     * @return 职工
     */
    @Override
    public List<ShopEmployee> selectShopEmployeeList(ShopEmployee shopEmployee) {
        return shopEmployeeMapper.selectShopEmployeeList(shopEmployee);
    }

    /**
     * 新增职工
     *
     * @param employeeVo 职工
     * @return 结果
     */
    @Override
    public int insertShopEmployee(EmployeeVo employeeVo) {
        ShopEmployee shopEmployee = new ShopEmployee();
        BeanUtils.copyProperties(employeeVo, shopEmployee);
        // 根据店铺名称查询店铺id并封装到员工信息中
        shopEmployee.setShopId(shopShopService.selectShopShopByShopName(employeeVo.getShopName()).get(0).getShopId());
        return shopEmployeeMapper.insertShopEmployee(shopEmployee);
    }


    /**
     * 修改职工
     *
     * @param shopEmployee 职工
     * @return 结果
     */
    @Override
    public int updateShopEmployee(ShopEmployee shopEmployee) {
        return shopEmployeeMapper.updateShopEmployee(shopEmployee);
    }

    /**
     * 批量删除职工
     *
     * @param employeeIds 需要删除的职工主键
     * @return 结果
     */
    @Override
    public int deleteShopEmployeeByEmployeeIds(Long[] employeeIds) {
        return shopEmployeeMapper.deleteShopEmployeeByEmployeeIds(employeeIds);
    }

    /**
     * 删除职工信息
     *
     * @param employeeId 职工主键
     * @return 结果
     */
    @Override
    public int deleteShopEmployeeByEmployeeId(Long employeeId) {
        return shopEmployeeMapper.deleteShopEmployeeByEmployeeId(employeeId);
    }
}
